package models.re.realData;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Query;

import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

import play.db.jpa.JPA;

import models.aaa.Asset;
import models.aaa.Node;
import models.re.IItem;
import models.re.IRank;

@Entity
@Indexed
public class AssetRank extends Node implements IRank {
	
	Double value = 0.0;
	
	@IndexedEmbedded(depth = 3)
	@ManyToOne(fetch=FetchType.LAZY)	
	private Asset source = null;
	
	@IndexedEmbedded(depth = 3)
	@ManyToOne(fetch=FetchType.LAZY)
	private Asset target = null;
	
	AssetRank() {
		
	}
	
	public static AssetRank findById(Long id) {
		return JPA.em().find(AssetRank.class, id);
	}
	
	public static void purge() {
		String sql = "DELETE FROM AssetRank";
        Query query = JPA.em().createQuery(sql);
        query.executeUpdate();
	}
	
	AssetRank(IItem source, IItem target, Double value) {
		this.source=(Asset)source;
        this.target=(Asset)target;  
        this.value=value;
	}

	@Override
	public IItem getTarget() {
		// TODO Auto-generated method stub
		return target;
	}

}
